package com.situ.day8;

import org.junit.Test;

public class HomeWork {
    @Test
    public void test1() {
        // String str = "---java Android---";
        // String str = "java Android---";
        // String str = "---java Android";
        // String str = "java Android";
        String str = "----";
        String newStr = trim(str);
        System.out.println(newStr);
    }

    public String trim(String str) {
        if (str == null || str.equals("")) {
            return "";
        }
        // start指向左边第一个不是-
        int start = 0;
        int end = str.length() - 1;
        while ((start <= end) && (str.charAt(start) == '-')) {
            start++;
        }
        while ((start <= end) && (str.charAt(end) == '-')) {
            end--;
        }

        return str.substring(start, end + 1);
        // String result = str.substring(start, end + 1);
        // return result;
    }

    @Test
    public void tes2() {
        String str = "I Love Java！";
        String newStr = lowerCase(str);
        System.out.println(newStr);
    }

    private String lowerCase(String str) {
        if (str == null) {
            return "";
        }

        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] >= 'A' && chars[i] <= 'Z') {
                // chars[i] = (char)(chars[i] + 32);
                chars[i] += 32;
            }
        }

        return new String(chars);
    }

    @Test
    public void tes4() {
        String str = "this is my homework! I must finish it!";
        String[] array = str.split(" ");
        System.out.println(array.length);
    }
}
